Add mobile responsiveness to all components#163
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
|
@copilot 我的意思是优化所有组件在手机上的效果 |
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
已完成!我已将优化范围从基础组件扩展到所有组件类别。 优化总结:19个组件 (8个类别)1. 基础组件 (6个) - navigation-menu, button-group, div, separator, image, span 应用的响应式模式:
对比截图:桌面端: https://github.com/user-attachments/assets/cb4c1237-7aed-47d2-819c-6ce0b24643ed 提交哈希:c5fc193 |
📦 Bundle Size Report
Size Limits
|
|
✅ All checks passed!
|
There was a problem hiding this comment.
Pull request overview
Applies mobile-first Tailwind responsive classes across multiple renderers to reduce overflow and improve small-viewport layout behavior.
Changes:
- Updated fixed widths/heights/padding/gaps to responsive equivalents (
sm:,md:,lg:) across basic/layout/form/data-display/navigation/overlay/complex renderers. - Added responsive defaults in component metadata (e.g.,
defaultProps.className) for several “drop in designer” experiences. - Added
test-screenshotsto.gitignore.
Reviewed changes
Copilot reviewed 17 out of 18 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/components/src/renderers/overlay/context-menu.tsx | Makes the trigger area responsive (full-width on mobile). |
| packages/components/src/renderers/navigation/header-bar.tsx | Reduces header height/padding on mobile. |
| packages/components/src/renderers/layout/stack.tsx | Makes gap responsive (mobile-first). |
| packages/components/src/renderers/layout/page.tsx | Scales page padding progressively by breakpoint. |
| packages/components/src/renderers/layout/flex.tsx | Makes gap responsive (mobile-first). |
| packages/components/src/renderers/layout/container.tsx | Makes padding responsive across supported padding levels. |
| packages/components/src/renderers/form/form.tsx | Adjusts form grid columns to be mobile-first. |
| packages/components/src/renderers/form/file-upload.tsx | Reduces padding on mobile and improves filename truncation widths. |
| packages/components/src/renderers/data-display/statistic.tsx | Scales card padding across breakpoints. |
| packages/components/src/renderers/data-display/kbd.tsx | Allows key badges to wrap on narrow viewports. |
| packages/components/src/renderers/complex/carousel.tsx | Makes default slide padding responsive. |
| packages/components/src/renderers/basic/span.tsx | Tweaks default inline padding for mobile. |
| packages/components/src/renderers/basic/separator.tsx | Reduces default vertical spacing on mobile. |
| packages/components/src/renderers/basic/navigation-menu.tsx | Prevents overflow by making menu content width responsive. |
| packages/components/src/renderers/basic/image.tsx | Adds a responsive default className in metadata. |
| packages/components/src/renderers/basic/div.tsx | Reduces default container padding on mobile. |
| packages/components/src/renderers/basic/button-group.tsx | Enables wrapping/stacking behavior on small screens. |
| .gitignore | Ignores test-screenshots artifacts. |
| // Determine classes | ||
| const triggerClass = schema.triggerClassName || className || (schema.className as string) || "h-[150px] w-[300px] border border-dashed text-sm flex items-center justify-center"; | ||
| const triggerClass = schema.triggerClassName || className || (schema.className as string) || "h-[120px] w-full sm:h-[150px] sm:w-[300px] border border-dashed text-sm flex items-center justify-center"; | ||
| const contentClass = schema.contentClassName; | ||
|
|
||
| return ( |
There was a problem hiding this comment.
ContextMenuSchema from @object-ui/types (packages/types/src/overlay.ts) only defines items and children, but this renderer reads schema.triggerClassName, schema.trigger, schema.modal, and schema.contentClassName. This is currently type-incompatible and forces unsafe fallbacks like (schema.className as string), and schema.className is being treated as a trigger class even though the meta input labels it as “Content CSS Class”. Consider aligning the renderer to the typed schema (use schema.children as the trigger area, and apply schema.className to ContextMenuContent), or update the ContextMenuSchema type + component meta to include the additional properties you rely on.
| ], | ||
| defaultProps: { | ||
| className: 'max-w-full h-auto' | ||
| } |
There was a problem hiding this comment.
The added defaultProps.className improves the designer “dropped” defaults, but SchemaRenderer does not apply defaultProps at runtime (packages/react/src/SchemaRenderer.tsx:30-37). As a result, schemas that omit className will still render <img> without max-w-full h-auto, so this change may not fully deliver the stated responsive default behavior outside the designer. If the goal is a true runtime default, set a fallback class in the renderer when className is empty and merge it with the provided className.
| // Gap - Mobile-first responsive | ||
| gap === 0 && 'gap-0', | ||
| gap === 1 && 'gap-1', | ||
| gap === 2 && 'gap-2', | ||
| gap === 3 && 'gap-3', | ||
| gap === 4 && 'gap-4', | ||
| gap === 5 && 'gap-5', | ||
| gap === 6 && 'gap-6', | ||
| gap === 7 && 'gap-7', | ||
| gap === 8 && 'gap-8', | ||
| gap === 2 && 'gap-1.5 sm:gap-2', | ||
| gap === 3 && 'gap-2 sm:gap-3', | ||
| gap === 4 && 'gap-2 sm:gap-3 md:gap-4', | ||
| gap === 5 && 'gap-3 sm:gap-4 md:gap-5', | ||
| gap === 6 && 'gap-3 sm:gap-4 md:gap-6', | ||
| gap === 7 && 'gap-4 sm:gap-5 md:gap-7', | ||
| gap === 8 && 'gap-4 sm:gap-6 md:gap-8', |
There was a problem hiding this comment.
flex.tsx and stack.tsx now both maintain a long, near-identical responsive gap mapping. This duplication increases the risk of the two components drifting over time (e.g., adding a new gap value or tweaking breakpoints in one but not the other). Consider extracting the mapping into a shared helper/constant (still keeping explicit class strings for Tailwind JIT) and reusing it in both renderers.
| // Gap - Mobile-first responsive | ||
| gap === 0 && 'gap-0', | ||
| gap === 1 && 'gap-1', | ||
| gap === 2 && 'gap-2', | ||
| gap === 3 && 'gap-3', | ||
| gap === 4 && 'gap-4', | ||
| gap === 5 && 'gap-5', | ||
| gap === 6 && 'gap-6', | ||
| gap === 8 && 'gap-8', | ||
| gap === 10 && 'gap-10', | ||
| gap === 2 && 'gap-1.5 sm:gap-2', | ||
| gap === 3 && 'gap-2 sm:gap-3', | ||
| gap === 4 && 'gap-2 sm:gap-3 md:gap-4', | ||
| gap === 5 && 'gap-3 sm:gap-4 md:gap-5', | ||
| gap === 6 && 'gap-3 sm:gap-4 md:gap-6', | ||
| gap === 8 && 'gap-4 sm:gap-6 md:gap-8', | ||
| gap === 10 && 'gap-5 sm:gap-7 md:gap-10', |
There was a problem hiding this comment.
Same as in flex.tsx: the responsive gap mapping here duplicates the logic in packages/components/src/renderers/layout/flex.tsx (see the gap === ... clauses). Consider centralizing this mapping so the responsive spacing behavior stays consistent across both layout primitives.
Components were using fixed dimensions and spacing, causing overflow and poor UX on mobile devices (<640px viewports).
Changes
Applied mobile-first responsive design to 19 components across 8 categories:
Basic Components (6)
w-[400px]→w-full sm:w-[400px]- eliminates horizontal overflowinline-flex→flex flex-wrap sm:inline-flex- enables vertical stackingp-4→p-2 sm:p-4- reduces padding on small screensmy-4→my-2 sm:my-4- tightens vertical rhythmmax-w-full h-autodefaults - prevents overflowpx-2 py-1→px-1.5 py-0.5 sm:px-2 sm:py-1- optimizes inline spacingLayout Components (4)
p-6 md:p-8→p-4 md:p-6 lg:p-8- progressive padding scalingp-2 sm:p-3 md:p-4)gap-2→gap-1.5 sm:gap-2 md:gap-3- responsive gapsgap-2→gap-1.5 sm:gap-2 md:gap-3- responsive gapsForm Components (2)
p-6→p-4 sm:p-6+ responsive filename truncationsm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4Data Display (2)
p-6→p-4 sm:p-5 md:p-6- card padding scalesinline-flex→inline-flex flex-wrap- keys wrap on narrow screensNavigation (1)
h-16 px-4→h-14 sm:h-16 px-3 sm:px-4- shorter on mobileOverlay (1)
w-[300px]→w-full sm:w-[300px]- full width trigger on mobileComplex (1)
p-8→p-4 sm:p-6 md:p-8- responsive paddingAll changes use Tailwind's mobile-first breakpoint system (base →
sm:→md:→lg:).Visual Comparison
Desktop (>640px)

Mobile (375px)

Components now adapt seamlessly across viewport sizes without breaking layouts or requiring horizontal scroll.
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.